package com.baichang.taoshunda.controller.mobile.delivery;

import com.baichang.framework.controller.BaseMobileController;
import com.baichang.framework.controller.IService;
import com.baichang.framework.excelption.ServiceException;
import com.baichang.taoshunda.controller.ControllerConstants;
import com.baichang.taoshunda.service.CashService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created by ${wushenglu} on 17/09/06.
 */
@Controller
@RequestMapping(ControllerConstants.CASH)
public class DeliveryCashMCtronller extends BaseMobileController {
    @Autowired
    private CashService cashService;

    /**
     * 商家提现列表
     *
     * @param request
     * @param response
     */
    @RequestMapping("/findCashList")
    public void findDeliveryCashList(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer disId = getInt(json, "disId", 0);
                Integer nowPage = getInt(json, "nowPage", 0);
                return cashService.findDeliveryCashList(disId,nowPage,20);
            }
        });
    }

    /**
     * 提现
     *
     * @param request
     * @param response
     */
    @RequestMapping("/cash")
    public void cash(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer disId = getInt(json, "disId", 0);
                Integer bankCardId = getInt(json, "bankCardId", 0);
                Double money = getDouble(json, "money", 0D);
                return cashService.cashByDelivery(disId, bankCardId, money);
            }
        });
    }
    /**
     * 余额列表
     *
     * @param request
     * @param response
     */
    @RequestMapping("/blanceList")
    public void blanceList(HttpServletRequest request, HttpServletResponse response) {
        initEncode(request, response, new IService() {
            @Override
            public Object init(HttpServletRequest request, HttpServletResponse response, String json) throws ServiceException {
                Integer disId = getInt(json, "disId", 0);
               String startTime=getString(json,"startTime","");
               String endTime=getString(json,"endTime","");
                Integer nowPage = getInt(json, "nowPage", 1);
                return cashService.blanceList(disId,startTime,endTime,nowPage,20);
            }
        });
    }
}
